package com.ayuer.chapter05;

public class AlgoHeapDemo {

    public static void main(String[] args) {
        //属于完全二叉树
        //基于线性数组存储-》堆
        //根据数组建堆
        int[] data = {1, 20, 3, 4, 5, 11, 7, 8, 9, 10};

        //从索引0开始存储，节点i的父节点存在(i-1)/2，i>0时
        //节点i的左子节点为2i+1，右节点为2i+2

        HeapPriorityQueue priorityQueue = new HeapPriorityQueue(100);

        for (int i = 0; i < data.length; i++) {
            priorityQueue.offer(new Priority(data[i], "string->" + data[i]));
        }

        for (int i = 0; i < data.length; i++) {
            Priority poll = priorityQueue.poll();
            System.out.println(poll.getPriority());
            System.out.println(poll.getValue());
        }

    }
}
